
const {Controller}=require('egg');

class userController extends Controller{
    async index(){//获取数据
        let {ctx}=this;
        let result=await this.ctx.service.userlist.index();
        if(result.length){
            ctx.body={
                code:1001,
                msg:'获取用户列表成功',
                result
            }
        }else{
            ctx.body={
                code:1002,
                msg:'获取用户列表失败'
            }
        }

    };
    async create(){//添加
        let {ctx}=this;
        let id=ctx.helper.createId(ctx.request.body.username)
        let result=await ctx.service.userlist.create({
            id,
            ...ctx.request.body
        });
        if(result.affectedRows){
            ctx.body={
                code:1001,
                msg:'添加成功'
            }
        }
    };
};

module.exports=userController;